/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.InternationalizableEntity;
import interfaces.InternationalizableEntityDescription;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import javax.faces.context.FacesContext;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "language_level")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "LanguageLevel.findAll", query = "SELECT l FROM LanguageLevel l"),
    @NamedQuery(name = "LanguageLevel.findByIdLanguageLevel", query = "SELECT l FROM LanguageLevel l WHERE l.idLanguageLevel = :idLanguageLevel"),
    @NamedQuery(name = "LanguageLevel.findByDescription", query = "SELECT l FROM LanguageLevel l WHERE l.description = :description"),
    @NamedQuery(name = "LanguageLevel.findByValue", query = "SELECT l FROM LanguageLevel l WHERE l.value = :value")})
public class LanguageLevel implements Serializable,InternationalizableEntity,Comparable<LanguageLevel> {
    @OneToMany(mappedBy = "minimumLanguageLevel", fetch = FetchType.LAZY)
    private List<SearchLanguageInfoRequerimentAndOperator> searchLanguageInfoRequerimentAndOperatorList;
    @OneToMany(mappedBy = "minimumLanguageLevel", fetch = FetchType.LAZY)
    private List<SearchLanguageInfoRequerimentOrOperator> searchLanguageInfoRequerimentOrOperatorList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_LANGUAGE_LEVEL")
    private Integer idLanguageLevel;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "DESCRIPTION")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Column(name = "VALUE")
    private Integer value;
    @OneToMany(mappedBy = "languageLevel")
    private List<CandidateLanguageInfo> candidateLanguageInfoList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "languageLevel")
    private List<LanguageLevelDescription> languageLevelDescriptionList;

    public LanguageLevel() {
    }

    public LanguageLevel(Integer idLanguageLevel) {
        this.idLanguageLevel = idLanguageLevel;
    }

    public LanguageLevel(Integer idLanguageLevel, String description, int value) {
        this.idLanguageLevel = idLanguageLevel;
        this.description = description;
        this.value = value;
    }

    public Integer getIdLanguageLevel() {
        return idLanguageLevel;
    }

    public void setIdLanguageLevel(Integer idLanguageLevel) {
        this.idLanguageLevel = idLanguageLevel;
    }

    @Override
    public String getDescription() {
//        String resDescription=description;
//        Locale currentLocale=FacesContext.getCurrentInstance().getViewRoot().getLocale();
//        if(!getLanguageLevelDescriptionList().isEmpty() && !currentLocale.equals(Locale.ENGLISH)){
//            String localeCode=currentLocale.getLanguage();
//            for(LanguageLevelDescription cd:getLanguageLevelDescriptionList()){
//                if(cd.getLanguage().getCode().equals(localeCode)){
//                    resDescription=cd.getDescription();
//                }
//            }
//        }
//        return resDescription;
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    @XmlTransient
    public List<CandidateLanguageInfo> getCandidateLanguageInfoList() {
        return candidateLanguageInfoList;
    }

    public void setCandidateLanguageInfoList(List<CandidateLanguageInfo> candidateLanguageInfoList) {
        this.candidateLanguageInfoList = candidateLanguageInfoList;
    }

    @XmlTransient
    public List<LanguageLevelDescription> getLanguageLevelDescriptionList() {
        return languageLevelDescriptionList;
    }

    public void setLanguageLevelDescriptionList(List<LanguageLevelDescription> languageLevelDescriptionList) {
        this.languageLevelDescriptionList = languageLevelDescriptionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idLanguageLevel != null ? idLanguageLevel.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LanguageLevel)) {
            return false;
        }
        LanguageLevel other = (LanguageLevel) object;
        if ((this.idLanguageLevel == null && other.idLanguageLevel != null) || (this.idLanguageLevel != null && !this.idLanguageLevel.equals(other.idLanguageLevel))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.LanguageLevel[ idLanguageLevel=" + idLanguageLevel + " ]";
    }

    @XmlTransient
    public List<SearchLanguageInfoRequerimentAndOperator> getSearchLanguageInfoRequerimentAndOperatorList() {
        return searchLanguageInfoRequerimentAndOperatorList;
    }

    public void setSearchLanguageInfoRequerimentAndOperatorList(List<SearchLanguageInfoRequerimentAndOperator> searchLanguageInfoRequerimentAndOperatorList) {
        this.searchLanguageInfoRequerimentAndOperatorList = searchLanguageInfoRequerimentAndOperatorList;
    }

    @XmlTransient
    public List<SearchLanguageInfoRequerimentOrOperator> getSearchLanguageInfoRequerimentOrOperatorList() {
        return searchLanguageInfoRequerimentOrOperatorList;
    }

    public void setSearchLanguageInfoRequerimentOrOperatorList(List<SearchLanguageInfoRequerimentOrOperator> searchLanguageInfoRequerimentOrOperatorList) {
        this.searchLanguageInfoRequerimentOrOperatorList = searchLanguageInfoRequerimentOrOperatorList;
    }

    @Override
    public Integer getId() {
        return getIdLanguageLevel();
    }

    @Override
    public List<? extends InternationalizableEntityDescription> getDescriptionsList() {
        return getLanguageLevelDescriptionList();
    }

    @Override
    public int compareTo(LanguageLevel o) {
        return this.getValue().compareTo(o.getValue());
    }
    
}
